//
//  YMHomeHealthMoreCell.m
//  YMMedical
//
//  Created by y s on 2023/7/19.
//

#import "YMHomeHealthMoreCell.h"
#import "YMHomeCycleScrollView.h"
#import "YMHomeHealthMoreItemCell.h"


@interface YMHomeHealthMoreCell ()<YMHomeCycleScrollViewDelegate>

/** banner */
@property (nonatomic, strong) YMHomeCycleScrollView *vCycle;
@property (nonatomic, strong) UIPageControl *pageControl;

@end

@implementation YMHomeHealthMoreCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - UI methods
- (void)setUI{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    
    [self.contentView addSubview:self.vCycle];
    [self.contentView addSubview:self.pageControl];

    [_vCycle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo([SFitUtil fit:15]);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo([SFitUtil fit:102]);
    }];
    [self.pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.height.mas_equalTo([SFitUtil fit:20]);
        make.top.equalTo(self.vCycle.mas_bottom).offset([SFitUtil fit:10]);
    }];
}

#pragma mark —- public methods
+ (CGFloat)getCellHeight{
    return [SFitUtil fit:102+15+40];
}
- (void)setArrItem:(NSArray *)arrItem{
    _arrItem = arrItem;
    self.vCycle.dataSource = arrItem;
    self.pageControl.numberOfPages = arrItem.count;
}
- (void)setCurrentIndex:(NSInteger)currentIndex{
    _currentIndex = currentIndex;
    self.pageControl.currentPage = currentIndex;
    self.vCycle.indexNow = currentIndex;
}

- (void)cardView:(YMHomeCycleScrollView *)bannerView didSelectedAtIndex:(NSInteger)index{
    //点击
    
}
- (void)cardView:(YMHomeCycleScrollView *)bannerView changeCurrentIndex:(NSInteger)index{
    //当前选中
    self.pageControl.currentPage = index;
    if (self.changeItemBlock){
        self.changeItemBlock(index);
    }
}



- (YMHomeCycleScrollView *)vCycle{
    if (_vCycle == nil){
        _vCycle = [YMHomeCycleScrollView cardViewWithFrame:CGRectZero dataSource:[[NSArray alloc] init]];
        _vCycle.delegate = self;
    }
    return _vCycle;
}
- (UIPageControl *)pageControl{
    if (_pageControl == nil){
        _pageControl = [[UIPageControl alloc] init];
        _pageControl.currentPage = 0;
        _pageControl.hidesForSinglePage = YES;
        _pageControl.pageIndicatorTintColor = [SUIUtil colorOf:STheme.H_D12 alpha:0.2];
        _pageControl.currentPageIndicatorTintColor = STheme.D12;
    }
    return _pageControl;
}



@end
